
<!--
 * @Author: [kangjie]
 * @Date: 2022-04-29 09:43:20
 * @LastEditors: [kangjie]
 * @LastEditTime: 2022-04-29 10:24:08
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>绘制圆</title>
  <script>
    window.onload=function(){
      // 1.获取画布
      var canvas=document.querySelector('canvas');
      // 2.获取画布上下文对象 获取画笔
      var context=canvas.getContext('2d');
      // 声明一个径向渐变对象  参数:小圆心半径x y r 大圆心半径 x y r
      var g=context.createRadialGradient(200,200,50,200,200,200);
      // 添加渐变色
      g.addColorStop(0,'red');
      g.addColorStop(0.25,'blue');
      g.addColorStop(0.5,'cyan');
      g.addColorStop(0.65,'green');
      g.addColorStop(0.75,'pink');
      g.addColorStop(1,'yellow');
      // 将渐变对象给到填充样式
      context.fillStyle=g;
      context.fillRect(0,0,400,400);
    }
  </script>
</head>
<body>
  <canvas width="400px" height="400px"></canvas>
</body>
</html>